<template>
  <div class="elHeader">
    <i></i>
    <template v-if="isLogin">
      <div class="right-login-info">
        <el-popover
          placement="bottom"
          width="auto"
          trigger="hover"
          popper-class="colorBox"
        >
          <ul class="colors">
            <li
              v-for="v in colors"
              :key="v"
              :class="[
                v,
                v === color || (v == 'default' && !color) ? 'active' : '',
              ]"
              @click="setColor(v)"
            ></li>
          </ul>
          <i class="system" slot="reference">设置</i>
          <!--  v-limit="`user:theme`" -->
        </el-popover>
        <el-dropdown type="text" size="medium">
          <i class="user">{{ userName }}</i>
          <el-dropdown-menu slot="dropdown" class="troila-popper colorBox">
            <el-dropdown-item @click.native="showDialog = true"
              >修改密码</el-dropdown-item
            >
            <!-- v-limit="`user:editPassword`" -->
            <el-dropdown-item @click.native="loginOut">退出</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>
    </template>
    <template v-else></template>
    <dialog-password v-model="showDialog" />
  </div>
</template>
<script>
import dialogPassword from './dialog/passwordForm'
export default {
  name: 'mainHeader',
  components: {
    dialogPassword,
  },
  data() {
    return {
      colors: ['default', 'gray', 'green', 'orange', 'red', 'black', 'purple'],
      showDialog: false,
    }
  },
  computed: {
    color() {
      return this.$store.state.color
    },
    isLogin() {
      return this.$store.getters.login
    },
    userName() {
      return this.$store.getters.name
    },
  },
  created() {},
  methods: {
    setColor(v) {
      this.$store.dispatch('setColor', v)
    },
    loginOut() {
      this.$store
        .dispatch('user/logout')
        .then(async () => {
          this.$router.push('/')
        })
        .catch(() => {})
    },
  },
}
</script>
<style scoped>
.elHeader {
  display: -webkit-flex;
  display: -moz-flex;
  display: flex;
  justify-content: space-between;
  align-items: center;
  /*padding:0 30px;*/
  width: 100%;
  padding: 0;
  background-color: #fff;
  height: 100%;
}
.elHeader .right-login-info {
  /* width:300px; */
  /* flex:0 0 300px; */
  display: -webkit-inline-flex;
  display: -moz-inline-block;
  display: inline-flex;
  justify-content: space-between;
  align-items: center;
  position: relative;
  font-size: 15px;
}
.right-login-info > * {
  margin-left: 14px;
  padding: 0 10px;
  font-size: 15px;
}
.right-login-info > *:last-child {
  margin: 0 20px 0 14px;
}
.right-login-info i {
  display: block;
  width: auto;
  height: 34px;
  line-height: 35px;
  opacity: 1;
  transition: opacity 0.15s ease;
  cursor: pointer;
}
.right-login-info i:hover {
  opacity: 0.8;
}
.right-login-info i::before {
  content: '';
  display: inline-block;
  vertical-align: top;
  height: 34px;
  margin-right: 10px;
}
.user::before {
  width: 25px;
}
.system::before {
  width: 18px;
}
.exit::before {
  width: 21px;
}
.colors {
  font-size: 0;
  padding: 0 2px;
}
.colors > li {
  display: inline-block;
  vertical-align: top;
  width: 14px;
  height: 14px;
  border-radius: 4px;
  margin-right: 10px;
  border: 1px solid #fff;
  cursor: pointer;
  transition: all 0.15s;
}
.colors > li:last-child {
  margin-right: 0;
}
.colors > li.default {
  background-color: #4d6ee8;
}
.colors > li.gray {
  background-color: #3c6995;
}
.colors > li.green {
  background-color: #18ab9a;
}
.colors > li.orange {
  background-color: #ff9b57;
}
.colors > li.red {
  background-color: #c96767;
}
.colors > li.black {
  background-color: #272730;
}
.colors > li.purple {
  background-color: #4b5071;
}
.colors > li.default.active,
.colors > li.default:hover {
  border-color: #4d6ee8;
}
.colors > li.gray.active,
.colors > li.gray:hover {
  border-color: #3c6995;
}
.colors > li.green.active,
.colors > li.green:hover {
  border-color: #18ab9a;
}
.colors > li.orange.active,
.colors > li.orange:hover {
  border-color: #ff9b57;
}
.colors > li.red.active,
.colors > li.red:hover {
  border-color: #c96767;
}
.colors > li.black.active,
.colors > li.black:hover {
  border-color: #272730;
}
.colors > li.purple.active,
.colors > li.purple:hover {
  border-color: #4b5071;
}
.colors > li::before {
  content: '';
  display: block;
  width: 12px;
  height: 12px;
  background: url('../../assets/images/icon/active.png') center center/100% 100%
    no-repeat;
  margin: 1px;
  opacity: 0;
  transform: scale(0);
  transition: all 0.15s;
}
.colors > li.active::before {
  opacity: 1;
  transform: scale(1);
}
.el-dropdown-menu--medium.colorBox {
  padding: 8px 0;
}
</style>